import { _decorator, sys, Asset, resources } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('MapUtil')
export class MapUtil{
    private static _instance: MapUtil = null!;
    public static get instance () {
        if (this._instance) {
            return this._instance;
        }

        this._instance = new MapUtil();
        return this._instance;
    }

    public tildSize = 148;
    public width = 0;
    public height = 0;

    // 动物脚印 后期优化可使用 不同的动物显示不同的脚印
    private footPrint:Node[] = [null,null,null,null];

    // 陷阱
    public mapTrap = new Map();
    // 河流
    public mapRiver = new Map();
    // 兽穴
    public mapBen = new Map();
    // 棋子
    public mapPieces = new Map();
    // 原始棋子数据
    public mapObjPieces = new Map();

    public getTiledKey(x,y):String{
        return x+"_"+y;
    }
    public getKey(x,y):String{
        // return (x+this.width/2)/this.tildSize+"_"+(y+this.height/2)/this.tildSize;
        return parseInt((x/this.tildSize).toFixed())+"_"+ parseInt((y/this.tildSize).toFixed());
    }

    public init(tildSize:number,width:number,height:number){
        this.tildSize = tildSize;
        this.width = width;
        this.height = height;
    }

}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.3/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.3/manual/zh/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.3/manual/zh/scripting/life-cycle-callbacks.html
 */

